<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>动态添加文件上传列表</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/upload.css}" rel="stylesheet">
    <script th:src="@{/js/jquery.min.js}"></script>
</head>
<body>
<div th:if="${uploadStatus}" style="color: green;" th:text="${uploadStatus}">上传成功</div>
<form th:action="@{/uploadFile}" method="post" enctype="multipart/form-data">
    上传文件：
    <input type="button" value="添加文件" onclick="add()"/>
    <div id="file" style="margin: 10px 0;"></div>
    <input id="submit" type="submit" value="上传" style="display: none;"/>
</form>
<script type="text/javascript">
    // 动态添加上传按钮
    function add() {
        var innerdiv = "<div>";
        innerdiv += '<input type="file" name="fileUpload" required="required">';
        innerdiv += '<input type="button" value="删除" onclick="remove(this)">';
        innerdiv += '</div>';
        $("#file").append(innerdiv);
        // 显示提交按钮
        $("#submit").css("display", "block");
    }

    // 删除当前行
    function remove(obj) {
        $(obj).parent().remove();
        if ($("#file div").length === 0) {
            $("#submit").css("display", "none");
            // 上传钮隐藏
        }
    }
</script>
</body>
</html>